﻿	<%@ taglib prefix='c' uri='http://java.sun.com/jsp/jstl/core' %>
	<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
	<%@ page import="com.cxx.purchasecharge.component.utils.ComponentConstants" %>
	
	<style type="text/css">
		#dlg-contact input, #dlg-contact select
		{
			width: 150px;
		}
		#dlg-contact #fm-contact div 
		{
			float: left;
			width: 155px;
			margin: 5px 30px;
		}
	</style>
	<script type="text/javascript">
		var contactGridDetailFormatter = function(index,row){
			return '<div class="ddv-contact" style="padding:5px 0"></div>';
		}
		var contactGridExpandRow = function(index,row){
			var ddv = $(this).datagrid('getRowDetail',index).find('div.ddv-contact');
			ddv.panel({
				height:65,
				border:false,
				cache:false,
				//href:'<c:url value='/contact/getModelByIdWithResponse.html' />?id='+row.id,
				content:"<style type='text/css'>.dv-table-contact td{border:0;}.dv-label-contact{font-weight:normal;color:#15428B;width:10%;}.dv-nonlabel-contact{width:23%;}</style>" + 
				"<table class='dv-table-contact' border='0' style='width:100%;'>" + 
				"<tr><td class='dv-label-contact'>地址:</td><td class='dv-nonlabel-contact'>" + row.address + "</td><td class='dv-label-contact'>旺旺:</td><td class='dv-nonlabel-contact'>" + row.wangWang + "</td><td class='dv-label-contact'>微信:</td><td class='dv-nonlabel-contact'>" + row.weiXin + "</td></tr>" + 
				"<tr><td class='dv-label-contact'>兴趣爱好:</td><td class='dv-nonlabel-contact'>" + row.interest + "</td><td class='dv-label-contact'>个人主页:</td><td class='dv-nonlabel-contact'>" + row.webSite + "</td><td class='dv-label-contact'>Skype:</td><td class='dv-nonlabel-contact'>" + row.skype + "</td></tr>" + 
				"<tr><td class='dv-label-contact'>部门:</td><td class='dv-nonlabel-contact'>" + row.dept + "</td><td class='dv-label-contact'>职位:</td><td class='dv-nonlabel-contact'>" + row.post + "</td><td class='dv-label-contact'></td><td class='dv-nonlabel-contact'></td></tr>" + 
				"</table>",
				onLoad:function(){
					$('#dg-contact').datagrid('fixDetailRowHeight',index);
				}
			});
			$('#dg-contact').datagrid('fixDetailRowHeight',index);
		}
		
		var newContactCallback = function () {
			$('#fm-contact input.easyui-combobox').combobox('reload');
			$('#fm-contact #userSignedTo').val('${sessionScope.login_user.userId}');
			$('#fm-contact #signUserFullName').textbox('setValue', '${sessionScope.login_user.fullName}');
			$('#dlg-contact #fm-contact #sharable').combobox('setValue', false);
			$('#dlg-contact #fm-contact #sharable').combobox('setText', '不可共享');
		}
		var editContactCallback = function () 
		{
			$('#fm-contact input.easyui-combobox').combobox('reload');
			var contact = $('#dg-contact').datagrid('getSelected');
			if(contact.sharable) 
			{
				$('#dlg-contact #fm-contact #sharable').combobox('setValue', contact.sharable);
				$('#dlg-contact #fm-contact #sharable').combobox('setText', '可共享');
			}
			else 
			{
				$('#dlg-contact #fm-contact #sharable').combobox('setValue', contact.sharable);
				$('#dlg-contact #fm-contact #sharable').combobox('setText', '不可共享');
			}
			if(contact.typeBean) 
			{
				$('#dlg-contact #fm-contact #contactTypeId').combobox('setValue', contact.typeBean.id);
			}
		}
		var onClickContactRow = function (rowIndex, rowData) 
		{
			$('#toolbar-contact #btn-editContact').linkbutton('enable');
			//$('#toolbar-contact #btn-deleteContact').linkbutton('enable');
		}
		var onLoadContactSuccess = function (data) 
		{
			$('#toolbar-contact #btn-editContact').linkbutton('disable');
			$('#toolbar-contact #btn-deleteContact').linkbutton('disable');
		}
		var onCheckAllContact = function(rows) 
		{
			$('#toolbar-contact #btn-deleteContact').linkbutton('enable');
		}
		var onUnCheckContact = function(rowIndex,rowData) 
		{
			var rows = $('#dg-contact').datagrid('getChecked');
			if (rows.length == 0) {
				$('#toolbar-contact #btn-deleteContact').linkbutton('disable');
			}
		}
		
		var onSelectCustomer = function(record) 
		{
			$('#dlg-contact #fm-contact #customerId').val(record.id);
		}
		var onChangeCustomer = function(newValue, oldValue) 
		{
			if(newValue == undefined) 
			{
				$('#dlg-contact #fm-contact #customerId').val('');
			}
		}
		var onShowContactType = function() 
		{
			$(this).combobox('reload', '<c:url value='/contactType/getAllModel.html' />');
		}
		var cellFormatter_contactType = function(value,row,index) 
		{
			if(row.typeBean) 
			{
				return row.typeBean.name;
			}
		}
    </script>

	<table id="dg-contact" title="<spring:message code="contact.contactManagement" />" class="easyui-datagrid" url="<c:url value='/contact/getAllModel.html' />"
		toolbar="#toolbar-contact" pagination="true" rownumbers="true" 
		singleSelect="true" checkOnSelect="true" selectOnCheck="false"
		fitColumns="true" sortName="name" sortOrder="asc" data-options="view:detailview, detailFormatter:contactGridDetailFormatter, onExpandRow:contactGridExpandRow, fit:true, onClickRow:onClickContactRow, onLoadSuccess:onLoadContactSuccess, onCheckAll:onCheckAllContact, onUncheckAll:onUnCheckContact, onCheck:onCheckAllContact, onUncheck:onUnCheckContact">
		<thead>
			<tr>
				<th data-options="field:'ck',checkbox:true"></th>
				<th data-options="field:'id',hidden:true"></th>
				<th field="name" width="50" sortable="true"><spring:message code="contact.name" /></th>
				<th field="customerId" width="50" hidden="true"></th>
				<th field="<%=ComponentConstants.CUSTOMER_NAME %>" width="50">客户/供应商</th>
				<th field="genderCode" width="50" sortable="true" data-options="formatter:cellFormatter_gender"><spring:message code="contact.genderCode" /></th>
				<th field="<%=ComponentConstants.PHONE %>" width="50" sortable="true"><spring:message code="contact.mobilePhone" /></th>
				<th field="<%=ComponentConstants.TECENT_QQ %>" width="50" sortable="true"><spring:message code="contact.qq" /></th>
				<th field="email" width="50" sortable="true"><spring:message code="contact.email" /></th>
				<th field="concernedBusiness" width="50" sortable="true"><spring:message code="contact.concernedBusiness" /></th>
				<th field="<%=ComponentConstants.CONTACT_TYPE %>" width="50" sortable="true" data-options="formatter:cellFormatter_contactType"><spring:message code="contact.type" /></th>
				<th field="userSignedTo" width="50"><spring:message code="customer.signUserId" /></th>
				<th field="sharable" width="50" sortable="true" data-options="formatter:cellFormatter_customerSharable"><spring:message code="customer.isSharable" /></th>
				
				<!-- put into detail view -->
				<th field="skype" width="50" hidden="true"><spring:message code="contact.skype" /></th>
				<th field="dept" width="50" hidden="true"><spring:message code="contact.dept" /></th>
				<th field="post" width="50" hidden="true"><spring:message code="contact.post" /></th>
				<th field="interest" width="50" hidden="true"><spring:message code="contact.interest" /></th>
				<th field="webSite" width="50" hidden="true"><spring:message code="contact.webSite" /></th>
				<th field="address" width="50" hidden="true"><spring:message code="contact.address" /></th>
				<th field="weiXin" width="50" hidden="true"><spring:message code="contact.weiXin" /></th>
				<th field="wangWang" width="50" hidden="true"><spring:message code="contact.wangWang" /></th>
			</tr>
		</thead>
	</table>
	
	<div id="toolbar-contact">
		<a href="javascript:void(0)" class="easyui-linkbutton" 
			iconCls="icon-add" plain="true" onclick="newModel('#dlg-contact', '<spring:message code="contact.newContact" />', '#fm-contact', '<c:url value='/contact/addModel.html' />', newContactCallback)" title="<spring:message code="contact.newContact" />"><spring:message code="contact.newContact" /></a> 
		<a id="btn-editContact" href="javascript:void(0)" class="easyui-linkbutton" disabled="true" 
			iconCls="icon-edit" plain="true" onclick="editModel('#dg-contact', '#dlg-contact', '<spring:message code="contact.editContact" />', '#fm-contact', '<c:url value='/contact/updateModel.html' />', editContactCallback)" title="<spring:message code="selectOneRow" /><spring:message code="contact.editContact" />"><spring:message code="contact.editContact" /></a> 
		<a id="btn-deleteContact" href="javascript:void(0)" class="easyui-linkbutton" disabled="true" 
			iconCls="icon-remove" plain="true" onclick="destroyMultipleModel('#dg-contact', '<spring:message code="contact.contact" />', '<c:url value='/contact/deleteModels.html' />')" title="<spring:message code="checkOneOrMultiple" /><spring:message code="contact.removeContact" />"><spring:message code="contact.removeContact" /></a>
		<span style="float: right; margin-right: 5px">
			<input class="easyui-searchbox" data-options="prompt:'<spring:message code="pleaseInputValue" />',searcher:doSearchContact" style="" />
		</span>
	</div>

	<div id="dlg-contact" class="easyui-dialog"
		style="width: 800px; height: 500px; padding:20px 5px;" closed="true"
		buttons="#dlg-buttons-contact" data-options="modal:true">
		<div style="width:100%;height:100%">
			<form id="fm-contact" class="fm" style="margin:0 auto;padding:0px;width:650px;height:100%;" method="post" novalidate>
				<div class="fitem divHidden">
					<input id="contaId" name="id" value="0">
				</div>
				<div class="fitem">
					<label><spring:message code="contact.name" />:</label> 
					<input name="name" class="easyui-textbox" data-options="required:true"
					validType="myRemote['<c:url value='/contact/checkExist.html' />', 'contactName', '#contaId']">
				</div>
				<div class="fitem">
					<label><spring:message code="contact.mobilePhone" />:</label> 
					<input name="phone" class="easyui-textbox" required="true" validType="phoneCheck">
				</div>
				<div class="fitem divHidden">
					<input id="customerId" name="customerId" />
				</div>
				<div class="fitem">
					<label>客户:</label> 
					<%-- <input id="customerName" name="<%=ComponentConstants.CUSTOMER_NAME %>"
						class="easyui-textbox" title="点击查找和选择客户" readonly="readonly"
						onclick="popupSearchAndSelectCustomerDialog()"
						onmouseover="focusAsPointer('#dlg-contact #fm-contact #customerName')" />
					<a href="javascript:void(0)" id="customer-del-contact-btn"
						class="easyui-linkbutton" iconCls="icon-remove" plain="true"
						title="删除客户"
						onclick="cleanInput(['#dlg-contact #fm-contact #customerId','#dlg-contact #fm-contact #customerName'])"></a> --%>
					<input id="customerName" name="<%=ComponentConstants.CUSTOMER_NAME %>" class="easyui-combobox" data-options="
						valueField:'id', 
						textField:'shortName', 
						onSelect: onSelectCustomer,
						onChange:onChangeCustomer,
						mode:'remote', 
						loader:customerLoader, 
						onBeforeLoad: function(param){
							setAutoCompleteUrl ('<c:url value='/customer/getCustomerByShortNameLike.html' />');
						}" />
				</div>
				
				<div class="fitem">
					<label><spring:message code="contact.genderCode" />:</label> 
					<select name="genderCode" class="easyui-combobox" panelHeight="auto" editable="false">
						<option value="MALE" selected="selected"><spring:message code="contact.option.male" /></option>
						<option value="FEMALE"><spring:message code="contact.option.female" /></option>
					</select>
				</div>
				
				<div class="fitem">
					<label><spring:message code="contact.type" />:</label> 
					<input id="contactTypeId" name="typeBean.id" class="easyui-combobox" editable="false" panelHeight="auto" 
						data-options="valueField:'id',textField:'name',method:'post',url:'', onShowPanel:onShowContactType">
				</div>
				<div class="fitem divHidden">
					<input id="userSignedTo" name="userSignedTo" readonly="readonly" />
				</div>
				<div class="fitem">
					<label><spring:message code="customer.signUserId" />:</label> 
					<input id="signUserFullName" name="signUserFullName" class="easyui-textbox" readonly="readonly" />
				</div>
				<%-- <div class="fitem divHidden">
					<input name="<%=ComponentConstants.CUSTOMER_NAME %>">
				</div>
				<div class="fitem divHidden">
					<input name="customerId">
				</div> --%>
				
				<div class="fitem">
					<label><spring:message code="contact.qq" />:</label> 
					<input name="tecentQq" class="easyui-numberbox">
				</div>
				<div class="fitem">
					<label><spring:message code="contact.email" />:</label> 
					<input name="email" class="easyui-textbox" validType="email">
				</div>
				<div class="fitem">
					<label><spring:message code="contact.wangWang" />:</label> 
					<input name="wangWang" class="easyui-textbox">
				</div>
				<div class="fitem">
					<label><spring:message code="contact.dept" />:</label> 
					<input name="dept" class="easyui-textbox">
				</div>
				<div class="fitem">
					<label><spring:message code="contact.post" />:</label> 
					<input name="post" class="easyui-textbox">
				</div>
				<div class="fitem">
					<label><spring:message code="contact.concernedBusiness" />:</label> 
					<input name="concernedBusiness" class="easyui-textbox">
				</div>
				<div class="fitem">
					<label><spring:message code="contact.interest" />:</label> 
					<input name="interest" class="easyui-textbox">
				</div>
				<div class="fitem">
					<label><spring:message code="contact.address" />:</label> 
					<input name="address" class="easyui-textbox">
				</div>
				<div class="fitem">
					<label><spring:message code="contact.webSite" />:</label> 
					<input name="webSite" class="easyui-textbox" validType="url">
				</div>
				<div class="fitem">
					<label><spring:message code="customer.isSharable" />:</label> 
					<select id="sharable" name="sharable" class="easyui-combobox" editable="false" required="true" panelHeight="auto">
						<option value="true" selected="selected"><spring:message code="customer.option.enSharable" /></option>
						<option value="false"><spring:message code="customer.option.unSharable" /></option>
					</select>
				</div>
			</form>
		</div>
	</div>
	<div id="dlg-buttons-contact">
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-ok" onclick="saveModel('#dg-contact', '#dlg-contact', '#fm-contact')"><spring:message code="save" /></a> 
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-cancel" onclick="javascript:$('#dlg-contact').dialog('close')"><spring:message code="cancel" /></a>
	</div>
